using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using BreukenWebsite.Models;

namespace BreukenWebsite.Controllers
{
    public class LeerlingBeheerController : Controller
    {

        BreukenRepository breukenRepository = new BreukenRepository();
        //
        // GET: /LeerlingBeheer/
        [Authorize(Roles = "admin")]
        public ActionResult Index()
        {
            var leerlingen = breukenRepository.FindAllLeerlingen();
            return View("Index", leerlingen);
        }

        //
        // GET: /LeerlingBeheer/Details/5

        [Authorize(Roles = "admin")]
        public ActionResult Details(int id)
        {
            var leerling = breukenRepository.GetLeerling(id);
            return View("Details", leerling);
        }

        //
        // GET: /LeerlingBeheer/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /LeerlingBeheer/Create

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /LeerlingBeheer/Edit/5

        [Authorize(Roles = "admin")]
        public ActionResult Edit(int id)
        {
            var leerling = breukenRepository.GetLeerling(id);
            return View("Edit", leerling);
        }

        //
        // POST: /LeerlingBeheer/Edit/5

        [Authorize(Roles = "admin")]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                Leerling leerling = breukenRepository.GetLeerling(id);
                leerling.klas = collection["klas"];
                breukenRepository.Save();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
